<template>
  <HHeader theme="white" :style="{ boxShadow: '0 2px 3px 2px rgba(0,0,0,.1)' }">
    <Row>
      <Cell width="1">
        <Button icon="h-icon-menu" size="l" noBorder @click="siderChange"></Button>
      </Cell>
      <Cell width="13">
        <Select :datas="searchData" :filterable="true" @change="change" no-border align="left" placeholder="全局搜索" :deletable="false"></Select>
      </Cell>
      <Cell width="10" align="right">
        <DropdownMenu @click="trigger" :datas="param" class-name="h-text-dropdown" :width="150">
          <span>{{ loginName }}</span>
        </DropdownMenu>
      </Cell>
    </Row>
  </HHeader>

</template>

<script>
export default {
  computed: {
    siderCollapsed() {
      return this.$store.state.menus.siderCollapsed;
    },
    loginName() {
      return this.$store.state.loginInfo.loginName;
    },
    searchData() {
      return this.$store.state.menus.searchData;
    },
  },
  data() {
    return {
      val: "",
      opened: false,
      param: [
        { label: "修改密码", value: "password", icon: "h-icon-user" },
        { divider: true },
        { label: "操作手册", value: "help", icon: "h-icon-help" },
        { divider: true },
        {
          label: "退出登录",
          value: "logout",
          icon: "h-icon-info",
        },
      ],
    };
  },
  methods: {
    trigger(code, data, event) {
      console.log(code);
      if (code == "password") {
        this.$router.push("/sysusers/passwd");
      } else if (code == "logout") {
        this.$Confirm("确定注销登录？", "提示").then(() => {
          this.$store.commit("LOGIN_FLAG", false);
          this.$store.commit("menuData", []);
          this.$axios.delete("/logout");
          location.href = "/";
        });
      } else if (code == "help") {
        window.open("操作手册.pdf");
      }
    },
    change(data) {
      if (!data) {
        return;
      }
      this.$store.commit("current", data.keyId);
      this.$store.commit("title", data.title);
      this.$router.push(data.keyId);
    },
    siderChange() {
      this.$store.commit("siderCollapsed");
    },
    copyText(e) {
      console.log(e.target.innerText);
      this.$Clipboard({
        text: e.target.innerText,
      });
    },
  },
};
</script>